using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region ALAttendee

	/// <summary>
	/// ALAttendee object for NHibernate mapped table 'ALAttendee'.
	/// </summary>
	[Serializable]
	public class ALAttendee : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _title;
		protected string _contactInfo;
		protected Application _application;
		protected Employee _employeeId;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public ALAttendee() { }

		public ALAttendee( string title, string contactInfo, Application application, Employee employeeId )
		{
			this._title = title;
			this._contactInfo = contactInfo;
			this._application = application;
			this._employeeId = employeeId;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string Title
		{
			get { return _title; }
			set
			{
				if ( value != null && value.Length > 100)
					throw new ArgumentOutOfRangeException("Invalid value for Title", value, value.ToString());
				_title = value;
			}
		}

		public string ContactInfo
		{
			get { return _contactInfo; }
			set
			{
				if ( value != null && value.Length > 50)
					value = value.Substring(0, 50 );
				_contactInfo = value;
			}
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

		public Employee EmployeeId
		{
			get { return _employeeId; }
			set { _employeeId = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is ALAttendee))
				throw new InvalidCastException("This object is not of type ALAttendee");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((ALAttendee)obj).Id);
					break;
				case "Title":
						relativeValue = ( this.Title != null ) ? this.Title.CompareTo(((ALAttendee)obj).Title) : -1;
					break;
				case "ContactInfo":
						relativeValue = ( this.ContactInfo != null ) ? this.ContactInfo.CompareTo(((ALAttendee)obj).ContactInfo) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (ALAttendee.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
